<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<link rel="icon" type="shortcut icon" th:href="@{/img/favicon.ico}" />
	<link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap.min.css}" />
	<link rel="stylesheet" type="text/css" th:href="@{/css/global.css}" />
	<link rel="stylesheet" th:href="@{/css/login.css}" />
	<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.3.0/font/bootstrap-icons.css">
	<title>语海社区 - 账号设置</title>
</head>
<body>
	<div class="nk-container">
		<!-- 头部 -->
		<header class="bg-dark sticky-top" th:replace="index::header"></header>

		<!-- 内容 -->
		<div class="main">
			<div class="container p-5 mt-3 mb-3">
				<!-- 修改密码 -->
				<h6 class="text-left text-info border-bottom pb-2 mt-2">修改个人信息</h6>
				<form class="mt-5" method="post" name="form" id="form">
					<div class="form-group row mt-4">
						<input type="hidden" id="infoId" name="infoId" th:value="${userInfo.getId()}">
						<label class="col-sm-2 col-form-label text-right">性别:</label>
						<div class="col-sm-10 d-flex align-items-center">
							<div class="form-check flex-grow-1">
								<input class="form-check-input" type="radio" name="gender" id="male" value="male" th:checked="${userInfo.getSex() == 1}">
								<label class="form-check-label" for="male">男性</label>
							</div>
							<div class="form-check flex-grow-1">
								<input class="form-check-input" type="radio" name="gender" id="female" value="female" th:checked="${userInfo.getSex() == 0}">
								<label class="form-check-label" for="female">女性</label>
							</div>
						</div>
					</div>
					<div class="form-group row mt-4">
						<label for="phone" class="col-sm-2 col-form-label text-right">电话号码:</label>
						<div class="col-sm-10">
							<input class="form-control"
								   th:value="${userInfo.getPhone()}"
								   id="phone" name="phone" placeholder="请输入手机号码" required pattern="\d{11}">
						</div>
					</div>
					<div class="form-group row mt-4">
						<label for="department" class="col-sm-2 col-form-label text-right">系名:</label>
						<div class="col-sm-10">
							<input class="form-control" id="department" name="department"
								   th:value="${userInfo.getDepartment()}" placeholder="就读的系名" required>
							<div class="invalid-feedback"></div>
						</div>
					</div>
					<div class="form-group row mt-4">
						<label for="specialities" class="col-sm-2 col-form-label text-right">专业名:</label>
						<div class="col-sm-10">
							<input class="form-control" id="specialities" name="specialities"
								   th:value="${userInfo.getSpecialities()}" placeholder="所学的专业" required>
							<div class="invalid-feedback"></div>
						</div>
					</div>
					<div class="form-group row mt-4">
						<label for="grade" class="col-sm-2 col-form-label text-right">年级:</label>
						<div class="col-sm-10">
							<select class="form-control" id="grade" name="grade" required>
								<option value="0">所在的年级</option>
								<th:block th:each="year : ${#numbers.sequence(2016, #dates.year(new java.util.Date()))}">
									<option th:value="${year}" th:text="${year}"></option>
								</th:block>
							</select>
							<div class="invalid-feedback"></div>
						</div>
					</div>

					<div class="form-group row mt-4">
						<label for="signature" class="col-sm-2 col-form-label text-right">个人简介:</label>
						<div class="col-sm-10">
							<textarea class="form-control" id="signature" name="signature" style="resize: none;" maxlength="100" rows="4"
									  th:value="${userInfo.getSignature()}" required></textarea>
							<div class="invalid-feedback"></div>
						</div>
					</div>
					<div class="form-group row mt-4">
						<div class="col-sm-2"></div>
						<div class="col-sm-10 text-center">
							<button type="button" id="publishBtn" name="publishBtn" class="btn btn-info text-white form-control">立即保存</button>
						</div>
					</div>
				</form>				
			</div>
		</div>

		<!-- 提示框 -->
		<div class="modal fade" id="hintModal" tabindex="-1" role="dialog" aria-labelledby="hintModalLabel" aria-hidden="true">
			<div class="modal-dialog modal-lg" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<h5 class="modal-title" id="hintModalLabel">提示</h5>
					</div>
					<div class="modal-body" id="hintBody"></div>
				</div>
			</div>
		</div>

		<!-- 尾部 -->
		<footer class="bg-dark" th:replace="index::footer"></footer>
	</div>

	<script th:src="@{/js/jquery-3.1.0.min.js}"></script>
	<script th:src="@{/js/popper.min.js}"></script>
	<script th:src="@{/js/bootstrap.min.js}"></script>
	<script th:src="@{/js/global.js}"></script>
	<script th:src="@{/js/bs-custom-file-input.js}"></script>
	<script th:src="@{/js/info-editor.js}"></script>
	<script>
		$(function(){
			bsCustomFileInput.init();
			$("#phone").on("change", function() {
				var phone = $(this).val();
				var pattern = /^\d{11}$/;

				if (!pattern.test(phone)) {
					alert("请输入有效的11位手机号码！");
					$(this).val(""); // 清空输入框
				}
			})
			$("#grade").on("change",function () {
				var grade = $(this).val();
				if (grade === 0){
					alert("请选择正确的年份");
					$(this).val(2023);
				}
			})
		});


	</script>
</body>
</html>
